﻿namespace HuaWei.CBR.QTJL
{
    using DevExpress.Utils;
    using DevExpress.XtraEditors;
    using DevExpress.XtraEditors.Controls;
    using DevExpress.XtraEditors.Repository;
    using DevExpress.XtraTreeList;
    using DevExpress.XtraTreeList.Columns;
    using DevExpress.XtraTreeList.Nodes;
    using HuaWei.CommClass;
    using HuaWei.DAI;
    using HuaWei.Windows.Forms;
    using System;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Windows.Forms;

    public class FrmCLSelect : Form
    {
        private string _str;
        private BindingSource bindingSource;
        private SimpleButton btnCancel;
        private TreeListColumn colBZ;
        private TreeListColumn colCLBH;
        private TreeListColumn colCLMC;
        private TreeListColumn colDFBL;
        private TreeListColumn colDJ;
        private TreeListColumn colDW;
        private TreeListColumn colJE;
        private TreeListColumn colSL;
        private DataSet dataSet = new DataSet();
        private DataTable dataTable = null;
        private SimpleButton GgxUfExf5;
        private IContainer icontainer = null;
        private PanelControl panelControl5;
        private RepositoryItemCheckEdit repositoryItemCheckEdit1;
        private RepositoryItemComboBox repositoryItemComboBox1;
        private RepositoryItemImageComboBox repositoryItemImageComboBox1;
        private RepositoryItemLookUpEdit repositoryItemLookUpEdit1;
        private RepositoryItemLookUpEdit repositoryItemLookUpEdit2;
        private TreeList tlQD;

        public FrmCLSelect()
        {
            this.InitializeComponent();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            base.DialogResult = System.Windows.Forms.DialogResult.Cancel;
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.icontainer != null))
            {
                this.icontainer.Dispose();
            }
            base.Dispose(disposing);
        }

        private void FrmCLSelect_Load(object sender, EventArgs e)
        {
            this.method();
        }

        private void GgxUfExf5_Click(object sender, EventArgs e)
        {
            string str = "";
            if (this.tlQD.Nodes.Count > 0)
            {
                this.method1(this.tlQD.Nodes, ref str);
            }
            if (!str.Equals(string.Empty))
            {
                DataRow[] rowArray = this.dataSet.Tables["CLQD"].Select("ID in (" + str + ")");
                DataRow row = null;
                foreach (DataRow row2 in rowArray)
                {
                    row = this.dataTable.NewRow();
                    row["pid"] = this._str;
                    row["CLBH"] = row2["CLBH"];
                    row["CLMC"] = row2["CLMC"];
                    row["DW"] = row2["DW"];
                    row["DFBL"] = row2["DFBL"];
                    row.EndEdit();
                    this.dataTable.Rows.Add(row);
                }
                base.DialogResult = System.Windows.Forms.DialogResult.OK;
            }
            else
            {
                MsgBox.ShowWarning("请选择需要的材料信息!");
            }
        }

        private void InitializeComponent()
        {
            this.icontainer = new Container();
            this.tlQD = new TreeList();
            this.colCLBH = new TreeListColumn();
            this.colCLMC = new TreeListColumn();
            this.colDW = new TreeListColumn();
            this.colDJ = new TreeListColumn();
            this.colSL = new TreeListColumn();
            this.colJE = new TreeListColumn();
            this.colDFBL = new TreeListColumn();
            this.colBZ = new TreeListColumn();
            this.bindingSource = new BindingSource(this.icontainer);
            this.repositoryItemImageComboBox1 = new RepositoryItemImageComboBox();
            this.repositoryItemComboBox1 = new RepositoryItemComboBox();
            this.repositoryItemLookUpEdit1 = new RepositoryItemLookUpEdit();
            this.repositoryItemLookUpEdit2 = new RepositoryItemLookUpEdit();
            this.repositoryItemCheckEdit1 = new RepositoryItemCheckEdit();
            this.panelControl5 = new PanelControl();
            this.btnCancel = new SimpleButton();
            this.GgxUfExf5 = new SimpleButton();
            this.tlQD.BeginInit();
            ((ISupportInitialize) this.bindingSource).BeginInit();
            this.repositoryItemImageComboBox1.BeginInit();
            this.repositoryItemComboBox1.BeginInit();
            this.repositoryItemLookUpEdit1.BeginInit();
            this.repositoryItemLookUpEdit2.BeginInit();
            this.repositoryItemCheckEdit1.BeginInit();
            this.panelControl5.BeginInit();
            this.panelControl5.SuspendLayout();
            base.SuspendLayout();
            this.tlQD.Columns.AddRange(new TreeListColumn[] { this.colCLBH, this.colCLMC, this.colDW, this.colDJ, this.colSL, this.colJE, this.colDFBL, this.colBZ });
            this.tlQD.DataSource = this.bindingSource;
            this.tlQD.Dock = DockStyle.Fill;
            this.tlQD.Font = new Font("宋体", 9f, FontStyle.Regular, GraphicsUnit.Point, 0x86);
            this.tlQD.ImageIndexFieldName = "";
            this.tlQD.Location = new Point(0, 0x1b);
            this.tlQD.Name = "tlQD";
            this.tlQD.OptionsView.ShowCheckBoxes = true;
            this.tlQD.ParentFieldName = "PID";
            this.tlQD.PreviewFieldName = "CLMC";
            this.tlQD.RepositoryItems.AddRange(new RepositoryItem[] { this.repositoryItemImageComboBox1, this.repositoryItemComboBox1, this.repositoryItemLookUpEdit1, this.repositoryItemLookUpEdit2, this.repositoryItemCheckEdit1 });
            this.tlQD.Size = new Size(0x2c2, 0x1e6);
            this.tlQD.TabIndex = 8;
            this.tlQD.TreeLineStyle = LineStyle.None;
            this.tlQD.BeforeCheckNode += new CheckNodeEventHandler(this.tlQD_BeforeCheckNode);
            this.tlQD.AfterCheckNode += new NodeEventHandler(this.tlQD_AfterCheckNode);
            this.colCLBH.Caption = "材料编号";
            this.colCLBH.FieldName = "CLBH";
            this.colCLBH.Name = "colCLBH";
            this.colCLBH.Visible = true;
            this.colCLBH.VisibleIndex = 0;
            this.colCLBH.Width = 0x6b;
            this.colCLMC.Caption = "材料名称";
            this.colCLMC.FieldName = "CLMC";
            this.colCLMC.Name = "colCLMC";
            this.colCLMC.Visible = true;
            this.colCLMC.VisibleIndex = 1;
            this.colCLMC.Width = 0x95;
            this.colDW.Caption = "单位";
            this.colDW.FieldName = "DW";
            this.colDW.Name = "colDW";
            this.colDW.Visible = true;
            this.colDW.VisibleIndex = 2;
            this.colDW.Width = 0x2c;
            this.colDJ.Caption = "单价";
            this.colDJ.FieldName = "DJ";
            this.colDJ.Name = "colDJ";
            this.colDJ.Visible = true;
            this.colDJ.VisibleIndex = 3;
            this.colDJ.Width = 0x33;
            this.colSL.Caption = "数量";
            this.colSL.FieldName = "SL";
            this.colSL.Name = "colSL";
            this.colSL.Visible = true;
            this.colSL.VisibleIndex = 4;
            this.colSL.Width = 0x3e;
            this.colJE.Caption = "金额";
            this.colJE.FieldName = "JE";
            this.colJE.Name = "colJE";
            this.colJE.Visible = true;
            this.colJE.VisibleIndex = 5;
            this.colJE.Width = 70;
            this.colDFBL.Caption = "垫付比例";
            this.colDFBL.FieldName = "DFBL";
            this.colDFBL.Name = "colDFBL";
            this.colDFBL.Visible = true;
            this.colDFBL.VisibleIndex = 6;
            this.colDFBL.Width = 0x48;
            this.colBZ.Caption = "备注";
            this.colBZ.FieldName = "BZ";
            this.colBZ.Name = "colBZ";
            this.colBZ.Visible = true;
            this.colBZ.VisibleIndex = 7;
            this.colBZ.Width = 130;
            this.bindingSource.DataMember = "CLQD";
            this.repositoryItemImageComboBox1.AutoHeight = false;
            this.repositoryItemImageComboBox1.Buttons.AddRange(new EditorButton[] { new EditorButton(ButtonPredefines.Combo) });
            this.repositoryItemImageComboBox1.Items.AddRange(new ImageComboBoxItem[] { new ImageComboBoxItem("", "1", 1), new ImageComboBoxItem("", "2", 5), new ImageComboBoxItem("", "3", 11) });
            this.repositoryItemImageComboBox1.Name = "repositoryItemImageComboBox1";
            this.repositoryItemComboBox1.AutoHeight = false;
            this.repositoryItemComboBox1.Buttons.AddRange(new EditorButton[] { new EditorButton(ButtonPredefines.Combo) });
            this.repositoryItemComboBox1.Items.AddRange(new object[] { "普通清单", "计日工", "暂定金" });
            this.repositoryItemComboBox1.Name = "repositoryItemComboBox1";
            this.repositoryItemLookUpEdit1.AutoHeight = false;
            this.repositoryItemLookUpEdit1.Buttons.AddRange(new EditorButton[] { new EditorButton(ButtonPredefines.Combo) });
            this.repositoryItemLookUpEdit1.Name = "repositoryItemLookUpEdit1";
            this.repositoryItemLookUpEdit2.AutoHeight = false;
            this.repositoryItemLookUpEdit2.Buttons.AddRange(new EditorButton[] { new EditorButton(ButtonPredefines.Combo) });
            this.repositoryItemLookUpEdit2.Columns.AddRange(new LookUpColumnInfo[] { new LookUpColumnInfo("code", "code", 20, FormatType.None, "", false, HorzAlignment.Default), new LookUpColumnInfo("value", "value") });
            this.repositoryItemLookUpEdit2.Name = "repositoryItemLookUpEdit2";
            this.repositoryItemCheckEdit1.AutoHeight = false;
            this.repositoryItemCheckEdit1.Name = "repositoryItemCheckEdit1";
            this.panelControl5.Controls.Add(this.btnCancel);
            this.panelControl5.Controls.Add(this.GgxUfExf5);
            this.panelControl5.Dock = DockStyle.Top;
            this.panelControl5.Location = new Point(0, 0);
            this.panelControl5.Name = "panelControl5";
            this.panelControl5.Size = new Size(0x2c2, 0x1b);
            this.panelControl5.TabIndex = 9;
            this.btnCancel.Dock = DockStyle.Left;
            this.btnCancel.Location = new Point(0x3e, 2);
            this.btnCancel.Name = "btnCancel";
            this.btnCancel.Size = new Size(60, 0x17);
            this.btnCancel.TabIndex = 1;
            this.btnCancel.Text = "取消";
            this.btnCancel.Click += new EventHandler(this.btnCancel_Click);
            this.GgxUfExf5.Dock = DockStyle.Left;
            this.GgxUfExf5.Location = new Point(2, 2);
            this.GgxUfExf5.Name = "btnOk";
            this.GgxUfExf5.Size = new Size(60, 0x17);
            this.GgxUfExf5.TabIndex = 0;
            this.GgxUfExf5.Text = "确定";
            this.GgxUfExf5.Click += new EventHandler(this.GgxUfExf5_Click);
            base.AutoScaleDimensions = new SizeF(6f, 12f);
            base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            base.ClientSize = new Size(0x2c2, 0x201);
            base.Controls.Add(this.tlQD);
            base.Controls.Add(this.panelControl5);
            base.Name = "FrmCLSelect";
            base.StartPosition = FormStartPosition.CenterParent;
            this.Text = "材料选择";
            base.Load += new EventHandler(this.FrmCLSelect_Load);
            this.tlQD.EndInit();
            ((ISupportInitialize) this.bindingSource).EndInit();
            this.repositoryItemImageComboBox1.EndInit();
            this.repositoryItemComboBox1.EndInit();
            this.repositoryItemLookUpEdit1.EndInit();
            this.repositoryItemLookUpEdit2.EndInit();
            this.repositoryItemCheckEdit1.EndInit();
            this.panelControl5.EndInit();
            this.panelControl5.ResumeLayout(false);
            base.ResumeLayout(false);
        }

        private void method()
        {
            IDataAccess access = DBHelp.IniIDA();
            this.dataSet.Merge(access.ExecuteDataSet("select * from CLQD" + Class28.smethod1(), CommandType.Text, "CLQD"));
            DHelp.AddColumnSelect(this.dataSet.Tables["CLQD"]);
            this.bindingSource.DataSource = this.dataSet.Tables["CLQD"];
        }

        private void method1(TreeListNodes treeListNodes, ref string _str1)
        {
            for (int i = 0; i < treeListNodes.Count; i++)
            {
                TreeListNode node = treeListNodes[i];
                if ((node.CheckState == CheckState.Checked) && !node.HasChildren)
                {
                    if (!_str1.Equals(string.Empty))
                    {
                        _str1 = _str1 + ",";
                    }
                    _str1 = _str1 + "'" + node["ID"].ToString() + "'";
                }
                this.method1(node.Nodes, ref _str1);
            }
        }

        public void SetClDt(DataTable dt, string pid)
        {
            this.dataTable = dt;
            this._str = pid;
        }

        private void tlQD_AfterCheckNode(object sender, NodeEventArgs e)
        {
            DevCCHelp.SetCheckedChildNodes(e.Node, e.Node.CheckState);
            DevCCHelp.SetCheckedParentNodes(e.Node, e.Node.CheckState);
        }

        private void tlQD_BeforeCheckNode(object sender, CheckNodeEventArgs e)
        {
            e.State = (e.PrevState == CheckState.Checked) ? CheckState.Unchecked : CheckState.Checked;
        }
    }
}

